<template>
  <div class="PlayMV" v-if="videos">
    <div class="title" @click="JumpToHomePage">
      <span class="iconfont icon-xiangzuo"></span>{{ itemname }}
    </div>
    <video :src="videos.url" class="videos" controls></video>
    <van-tabs>
      <van-tab title="最新评论">
        <div class="Comment-content">
          <div
            v-for="(item, index) in comment"
            :key="index"
            class="CommentMusic"
          >
            <div
              class="backgroundImage"
              :style="'background-image: url(' + item.user.avatarUrl + ')'"
            ></div>
            <div class="nickname">
              <h1>{{ item.user.nickname }}</h1>
              <h2>{{ item.timeStr }}</h2>
            </div>
            <div class="give-the-thumbs-up" @click="givethes(item)">
              {{ item.likedCount }}
              <span v-show="!item.liked" class="iconfont icon-dianzan"></span>
              <span
                v-show="item.liked"
                class="iconfont icon-dianzan iconfontred"
              ></span>
            </div>
            <div class="content">
              <p>{{ item.content }}</p>
            </div>
          </div>
        </div>
        <div class="AddComment">
          <input type="text" placeholder="输入热评" v-model="sr" /><span
            class="iconfont icon-wangyiyunyinle1-copy"
          ></span>
          <p @click="Comment">发送</p>
        </div></van-tab
      >
      <van-tab title="相关视频">
        <div
          class="Related-video"
          v-for="(item, index) in Relatedvideo"
          :key="index"
          @click="Related(item.id)"
        >
          <div
            class="imgs"
            :style="'background-image: url(' + item.picUrl + ')'"
          ></div>
          <div>
            <h1>{{ item.artistName }}</h1>
            <h2>{{ item.name }}</h2>
          </div>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>
<script>
import {
  getMvUrl,
  getCommentMV,
  getRelatedAllvideo,
  getMvDetail,
  // getVideourl
} from "../api/ranking";
import { getComment, getCommenLikeId } from "../api/recommend";
import { Toast } from "vant";
export default {
  data() {
    return {
      videos: null,
      comment: null,
      sr: "",
      Relatedvideo: null,
      itemname: null,
    };
  },
  methods: {
    Related(id) {
      getMvUrl({ id: id }).then((data) => {
        this.videos = data.data;
      });
      getCommentMV({ id: id }).then((data) => {
        this.comment = data.comments;
      });
      getRelatedAllvideo({ id: id }).then((data) => {
        this.Relatedvideo = data.data;
      });
      // getVideourl({id:id}).then(data=>{
      //   console.log(data);
      // })
    },
    getMvUrlFUN() {
      getMvUrl({ id: this.$route.query.id }).then((data) => {
        this.videos = data.data;
      });
    },
    getCommentMVFUN() {
      getCommentMV({ id: this.$route.query.id }).then((data) => {
        this.comment = data.comments;
      });
    },
    getRelatedAllvideoFUN() {
      getRelatedAllvideo({ id: this.$route.query.id }).then((data) => {
        this.Relatedvideo = data.result;
        console.log(data);
      });
    },
    getMvDetailFUN() {
      getMvDetail({ mvid: this.$route.query.id }).then((data) => {
        console.log(data);
        this.itemname = data.data.name;
      });
    },
    Comment() {
      getComment({ type: 1, id: this.$route.query.id, content: this.sr });
      this.sr = null;
    },
    JumpToHomePage() {
      this.$router.go("-1");
    },
    givethes(item) {
      console.log(item);
      item.liked = !item.liked;
      if (item.liked == false) {
        Toast("取消点赞");
        getCommenLikeId({
          id: item.commentId,
          cid: this.$route.query.id,
          t: 0,
          type: 1,
        });
      } else {
        Toast("点赞成功");
        getCommenLikeId({
          id: item.commentId,
          cid: this.$route.query.id,
          t: 1,
          type: 1,
        });
      }
    },
  },
  created() {
    this.getMvUrlFUN();
    this.getCommentMVFUN();
    this.getRelatedAllvideoFUN();
    this.getMvDetailFUN();
  },
};
</script>
<style lang="less">
.PlayMV {
  .van-tabs__content {
    .van-tab__pane {
      width: 100%;
      height: 100vh;
      .Related-video {
        width: 90%;
        height: 10%;
        margin: 10px auto;
        display: flex;
        div {
          width: 70%;
          h1 {
            padding: 0;
            margin-left: 10px;
            font-size: 16px;
          }
          h2 {
            margin-left: 10px;
            font-size: 14px;
          }
        }
        .imgs {
          flex: 1;
          background-size: 100%;
          background-repeat: no-repeat;
        }
      }
    }
  }
  .title {
    height: 40px;
    line-height: 40px;
    font-size: 16px;
    color: white;
    font-weight: 500;
    background-color: #d44439;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    padding: 0 30% 0 0;
    span {
      margin: 0 2%;
    }
  }
  .videos {
    width: 100%;
  }
  .Comment-area {
    margin: 10px 0;
  }
  .Comment-content {
    width: 100%;
    padding-bottom: 8%;
    .CommentMusic {
      margin-top: 10px;
      width: 95%;
      padding-left: 3%;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      .backgroundImage {
        width: 38px;
        height: 38px;
        background-size: 100%;
        border-radius: 50%;
        margin-right: 2%;
      }
      .nickname {
        flex: 1;
        color: #838383;
      }
      h1 {
        padding: 0px;
        font-size: 14px;
      }
      h2 {
        font-size: 8px;
      }
      .give-the-thumbs-up {
        position: relative;
        padding-right: 5%;
        line-height: 12px;
        font-size: 12px;
        color: #838383;
        span {
          position: absolute;
          right: -2%;
          color: #838383;
        }
        .iconfontred {
          color: red;
        }
      }
      .content {
        margin-top: 1%;
        width: 88%;
        margin-left: 12%;
        font-size: 14px;
        border-bottom: 1px solid #b4b4b4;
        padding-bottom: 2%;
      }
    }
  }
  .AddComment {
    position: fixed;
    bottom: 0px;
    width: 100%;
    height: 40px;
    border-top: 1px solid #838383;
    background-color: white;
    display: flex;
    align-items: center;
    input {
      width: 80%;
      height: 100%;
      border: none;
      padding-left: 5%;
    }
    span {
      font-size: 20px;
      color: red;
    }
  }
}
</style>